package com.link.play.fit.ai.ui.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

import com.link.play.fit.ai.utils.ScreenUtil;


public class SemiCircleView extends View {

    private Paint paint;
    private RectF rectF;
    private float startAngle = 0; // 起始角度，用于动画

    public SemiCircleView(Context context) {
        super(context);
        init();
    }

    public SemiCircleView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        paint = new Paint();
        paint.setColor(0xFFFFFFFF); // 设置半圆颜色
        paint.setStyle(Paint.Style.STROKE); // 设置画笔为描边模式
        paint.setStrokeWidth(6); // 设置描边宽度
        paint.setAntiAlias(true); // 抗锯齿

    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        // 定义绘制半圆的矩形区域
        float size = ScreenUtil.Companion.pxToDp(9);
//        rectF = new RectF(20, 20, w - 20, h - 20);
        rectF = new RectF(size, size, w - size, h - size);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        // 绘制半圆
        canvas.drawArc(rectF, startAngle, 270, false, paint);

    }

    // 设置起始角度
    public void setStartAngle(float angle) {
        this.startAngle = angle;
        invalidate(); // 重绘
    }
}